package com.red.battleworm.element {
	
	import org.cove.ape.*;	
	
//	import com.red.battleworm.AppMain;	
	import com.red.battleworm.model.MapProxy;

	import flash.utils.getTimer;

	/**
	 * @author zhangs
	 */
	public class Bullet extends AbstractElement {
		public var SPEEDMAGNITUDE : Number = 20;
		private static var WIDTH : Number = 6;
		private static var HEIGHT : Number = 6;
		
		public function Bullet(px:Number, py:Number, rotation:Number, scale:Number) {
			super();
			
			body = new RectangleParticle(px-WIDTH/2, py-HEIGHT/2, WIDTH, HEIGHT);
			body.setStyle(0, MapProxy.COLOR, 1, MapProxy.COLOR);
			body.friction = 0.5;
			body.elasticity = 0.2;
			
			addParticle(body);
			
			var maxspeed : Number = SPEEDMAGNITUDE * scale;
			if ((rotation%180+180)%180 == 90) {
				speed.y = maxspeed;
			} else if ((rotation%180+180)%180 == -90) {
				speed.y = -maxspeed;
			} else {
				var r : Number = rotation / 180 * Math.PI;
				var sin : Number = Math.sin(r);
				var cos : Number = Math.cos(r);
				speed.x = maxspeed * cos;
				speed.y = maxspeed * sin;
			}
			setSpeed(speed);
			body.velocity = this.speed;
		}

		public override function run() : void {
//			body.addForce(new VectorForce(false, 0, -10));
			super.run();
		}
	}
}
